﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WQMS.Model;
using WQMS.Services;

namespace WQMS.Api.Controllers
{
    
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        
        LoginServices loginServices = new LoginServices();
        [HttpPost]
        public async Task<MessageModel<string>> Login(string username = "", string password = "")
        {
            if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password)) 
            {
                return new MessageModel<string>() 
                {
                    success = false,
                    msg = "用户名或密码不能为空",
                };
            }
            var list = await loginServices.Query(c => c.UserID == username && c.PassWord == password);
            if (list.Count > 0) 
            {
                return new MessageModel<string>()
                {
                    success = true,
                    msg = "登录成功!",
                };
            }
            return new MessageModel<string>()
            {
                success = true,
                msg = "登录失败!",
            };
        }
    }
}
